﻿package mortal.game.proxy
{
    import Framework.Util.*;
    import Message.Game.*;
    import com.gengine.debug.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.error.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.guide.*;
    import mortal.game.view.shop.*;
    import mortal.game.view.shopMall.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.mvc.core.*;

    public class ShopProxy extends Proxy
    {
        private var _shopCache:ShopCache;

        public function ShopProxy()
        {
            this.init();
            return;
        }// end function

        private function init() : void
        {
            this._shopCache = this.cache.shop;
            return;
        }// end function

        public function buy(param1:ShopItemData, param2:BaseItem = null) : void
        {
            var _loc_3:Object = {shopItemData:param1, item:param2};
            rmi.iShopPrx.buy_async(new AMI_IShop_buy(this.buyItemSuccess, null, _loc_3), param1.npcId, param1.tShopSell.shopCode, param1.tShopSell.itemCode, param1.num, 1, param1.type == 0 ? (false) : (true), param1.useNum);
            return;
        }// end function

        private function buyItemSuccess(param1:AMI_IShop_buy) : void
        {
            var _loc_5:Point = null;
            var _loc_6:Dictionary = null;
            var _loc_7:SShopBuyPlayerInfo = null;
            var _loc_8:int = 0;
            var _loc_2:* = param1.userObject;
            var _loc_3:* = _loc_2["item"] as BaseItem;
            if (_loc_3)
            {
                _loc_5 = _loc_3.localToGlobal(GameConst.yellowPoint);
                FlyToNavbarTool.flyBitmapOriginalToPack(_loc_3.bitmapdata, _loc_5);
            }
            var _loc_4:* = _loc_2["shopItemData"] as ShopItemData;
            if (_loc_4.tShopSell.maxBuyLimit > 0)
            {
                _loc_6 = Cache.instance.shop.buyRecords;
                _loc_8 = _loc_4.tShop.shareBuyRecordShop != 0 ? (_loc_4.tShop.shareBuyRecordShop) : (_loc_4.tShop.code);
                if (_loc_6[_loc_8] == null)
                {
                    _loc_6[_loc_8] = new Dictionary();
                }
                if (_loc_6[_loc_8][_loc_4.tShopSell.itemCode] == null)
                {
                    _loc_6[_loc_8][_loc_4.tShopSell.itemCode] = new SShopBuyPlayerInfo();
                    (_loc_6[_loc_8][_loc_4.tShopSell.itemCode] as SShopBuyPlayerInfo).buyDt = ClockManager.instance.nowDate;
                }
                (_loc_6[_loc_8][_loc_4.tShopSell.itemCode] as SShopBuyPlayerInfo).amount = (_loc_6[_loc_8][_loc_4.tShopSell.itemCode] as SShopBuyPlayerInfo).amount + _loc_4.num;
                NetDispatcher.dispatchCmd(ServerCommand.ShopLimitItemBuySuccess, null);
            }
            if (BuyItemWin.isViewShow && BuyItemWin.instance.shopData.itemInfo.code == _loc_4.itemInfo.code)
            {
                BuyItemWin.instance.hide();
            }
            if (BuyPropWin.isViewShow && BuyPropWin.instance.shopData.itemInfo.code == _loc_4.itemInfo.code)
            {
                BuyPropWin.instance.hide();
            }
            if (TipsBuyItemWin.isViewShow && TipsBuyItemWin.instance.shopData.itemInfo.code == _loc_4.itemInfo.code)
            {
                TipsBuyItemWin.instance.hide();
            }
            return;
        }// end function

        public function buyAndUse(param1:int, param2:int, param3:int, param4:int, param5:int) : void
        {
            rmi.iShopPrx.buyAndUse_async(new AMI_IShop_buyAndUse(this.buySuccess, this.buyFail), param1, param2, param3, param4, param5);
            return;
        }// end function

        private function buySuccess(param1:AMI_IShop_buyAndUse) : void
        {
            return;
        }// end function

        private function buyFail(param1:Exception) : void
        {
            MsgManager.showRollTipsMsg(ErrorCode.getErrorStringByCode(param1.code));
            return;
        }// end function

        public function buyBack(param1:Array) : void
        {
            rmi.iShopPrx.buyBack_async(new AMI_IShop_buyBack(this.buyBackSuccess, this.buyBackFail), param1);
            return;
        }// end function

        private function buyBackSuccess(param1:AMI_IShop_buyBack) : void
        {
            Log.debug("回购成功");
            return;
        }// end function

        private function buyBackFail(param1:Exception) : void
        {
            Log.debug("回购失败");
            MsgManager.showRollTipsMsg(ErrorCode.getErrorStringByCode(param1.code));
            return;
        }// end function

        public function getSaleConfig() : void
        {
            rmi.iActiveShop.getSaleConfig_async(new AMI_IPanicBuy_getSaleConfig(this.onGetCfg, this.onFail));
            return;
        }// end function

        private function onGetCfg(param1:AMI_IPanicBuy_getSaleConfig) : void
        {
            return;
        }// end function

        public function closeSalePanel() : void
        {
            rmi.iActiveShop.closeSalePanel_async(new AMI_IPanicBuy_closeSalePanel(null, this.onFail));
            return;
        }// end function

        public function buySellItem(param1:int, param2:int, param3:BaseItem, param4:int, param5:int = 0, param6:Array = null) : void
        {
            var buySellItemSuccess:Function;
            var shopCode:* = param1;
            var itemCode:* = param2;
            var item:* = param3;
            var amount:* = param4;
            var useAmount:* = param5;
            var values:* = param6;
            buySellItemSuccess = function (param1:AMI_IPanicBuy_buySellItem) : void
            {
                var _loc_3:Point = null;
                var _loc_2:* = param1.userObject as BaseItem;
                if (_loc_2)
                {
                    _loc_3 = _loc_2.localToGlobal(GameConst.yellowPoint);
                    FlyToNavbarTool.flyBitmapOriginalToPack(_loc_2.bitmapdata, _loc_3);
                }
                return;
            }// end function
            ;
            rmi.iActiveShop.buySellItem_async(new AMI_IPanicBuy_buySellItem(buySellItemSuccess, this.onFail, item), shopCode, itemCode, amount, useAmount, values);
            return;
        }// end function

        private function onFail(param1:Exception) : void
        {
            MsgManager.showRollTipsMsg(ErrorCode.getErrorStringByCode(param1.code));
            return;
        }// end function

        public function getPanicBuyConfig() : void
        {
            rmi.iPanicBuyPrx.getPanicBuyConfig_async(new AMI_IPanicBuy_getPanicBuyConfig(this.getConfigSuccess));
            return;
        }// end function

        private function getConfigSuccess(param1:AMI_IPanicBuy_getPanicBuyConfig, param2:SPanicBuyMsg) : void
        {
            Cache.instance.secKilling.sPanicBuyMsg = param2;
            NetDispatcher.dispatchCmd(ServerCommand.secKillingItemListUpdate, param2);
            return;
        }// end function

        public function closePanicBuyPanel() : void
        {
            rmi.iPanicBuyPrx.closePanicBuyPanel_async(new AMI_IPanicBuy_closePanicBuyPanel());
            return;
        }// end function

        public function buyPanicItem(param1:int, param2:int, param3:BaseItem) : void
        {
            rmi.iPanicBuyPrx.buyItem_async(new AMI_IPanicBuy_buyItem(this.panicSuccess, null, param3), param1, param2);
            return;
        }// end function

        private function panicSuccess(param1:AMI_IPanicBuy_buyItem) : void
        {
            var _loc_3:Point = null;
            var _loc_2:* = param1.userObject as BaseItem;
            if (_loc_2)
            {
                _loc_3 = _loc_2.localToGlobal(GameConst.yellowPoint);
                FlyToNavbarTool.flyBitmapOriginalToPack(_loc_2.bitmapdata, _loc_3);
            }
            return;
        }// end function

    }
}
